package czy.demo.config.shiro;

import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.biz.web.filter.authc.listener.LoginListener;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/* 自定义登录监听器 */
@Component
public class DefaultLoginListener implements LoginListener {

    private static final Logger logger = LoggerFactory.getLogger(DefaultLoginListener.class);

    @Override
    public void onFailure(AuthenticationToken token, Exception ex, ServletRequest request, ServletResponse response) {
        logger.error("用户"+token.getPrincipal()+"登录失败",ex);
    }

    @Override
    public void onSuccess(AuthenticationToken token, Subject subject, ServletRequest request, ServletResponse response) {
        logger.debug("用户"+token.getPrincipal()+"登录成功");
    }
}
